package cn.baizhi.controller;


import cn.baizhi.entity.Group;
import cn.baizhi.service.GroupService;
import cn.baizhi.vo.GroupDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/groups")
public class GroupController {

    private static final Logger log = LoggerFactory.getLogger(GroupController.class);

    @Autowired
    private GroupService groupService;




    @GetMapping
    public ResponseEntity<List<GroupDTO>> selectAll(){

        List<GroupDTO> groupVos = groupService.selectAll();

        return new ResponseEntity<>(groupVos,HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Group> add(@RequestBody Group group){

        groupService.save(group);
        return new ResponseEntity<>(group,HttpStatus.OK);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Group> selectOne(@PathVariable("id") String id){
        Group group = groupService.getById(id);

        return new ResponseEntity<>(group,HttpStatus.OK);
    }

}

